package com.bc.bcsellerapihttp.controller;

import com.bc.bcapi.service.T_ProjectService;
import com.bc.bcapi.service.T_Project_acceptsService;
import com.bc.bcapi.service.T_Project_typeService;
import com.bc.bcmodel.SellerUserInfo;
import com.bc.bcmodel.domain.T_Project_acceptsModel;
import com.bc.bcmodel.domain.T_Project_typeModel;
import com.bc.bcmodel.domain.T_User_seller_infoModel;
import com.bc.bcmodel.req.ProjectGetByIdReq;
import com.bc.bcmodel.req.ProjectSetReq;
import com.bc.bcsellerapihttp.common.UserContext;
import com.bc.commonentity.common.JsonResult;
import com.bc.commonentity.enums.HttpReturnRnums;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Name ProjectController
 * @Description
 * @Author douhaichao
 * @Date 2018/8/18 21:14
 * @Version 1.0
 **/
@Api("项目相关")
@RestController
@RequestMapping("project")
public class ProjectController {

    @Autowired
    T_Project_typeService t_project_typeService;
    @Autowired
    T_Project_acceptsService t_project_acceptsService;
    @Autowired
    T_ProjectService t_projectService;

    @ApiOperation("获取项目类型")
    @RequestMapping(value = "gettype", method = RequestMethod.GET)
    public JsonResult getType(HttpServletRequest request) {
        return new JsonResult(t_project_typeService.getType(request));
    }

    @ApiOperation("获取可接受币种")
    @RequestMapping(value = "getaccepts", method = RequestMethod.GET)
    public JsonResult getAccepts() {
        JsonResult js = new JsonResult();
        js.setData(t_project_acceptsService.getAllList(null));
        return js;
    }

    @ApiOperation("ICO创建；新增项目/修改项目")
    @RequestMapping(value = "set", method = RequestMethod.POST)
    public JsonResult set(@RequestBody ProjectSetReq req) {
        try {
            SellerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
            if (userInfo == null) {
                return new JsonResult(HttpReturnRnums.NOT_LOGIN);
            }
            req.setUser_id(userInfo.getUser_id());
            return t_projectService.setProjectTmp(req);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return new JsonResult(HttpReturnRnums.SystemError);
        }
    }

    @ApiOperation("ICO查询；通过pid获取项目详情")
    @RequestMapping(value = "getbypid", method = RequestMethod.GET)
    public JsonResult getbypid() {
        ProjectGetByIdReq req = new ProjectGetByIdReq();
        SellerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        try {
            if (userInfo == null) {
                return new JsonResult(HttpReturnRnums.NOT_LOGIN);
            }
            req.setUser_id(userInfo.getUser_id());
            return t_projectService.getbypid(req);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return new JsonResult(HttpReturnRnums.SystemError);
        }
    }

    @ApiOperation("ICO审核信息查询；通过pid获取项目状态")
    @RequestMapping(value = "getstatusbypid", method = RequestMethod.GET)
    public JsonResult getStatusByPid() {
        ProjectGetByIdReq req = new ProjectGetByIdReq();
        SellerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        if (userInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }
        try {
            req.setUser_id(userInfo.getUser_id());
            return t_projectService.getStatusByPid(req);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return new JsonResult(HttpReturnRnums.SystemError);
        }
    }

    @ApiOperation("设置标记当前项目已签约")
    @RequestMapping(value = "setcontractbypid", method = RequestMethod.GET)
    public JsonResult setContractByPid() {
        SellerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        if (userInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }
        String user_id = userInfo.getUser_id();
        return t_projectService.setContractByPid(user_id);
    }

}
